﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Collections;
using GPCSC.Web;

namespace GPCSC.Web.WBWZ
{
    public partial class newsList : PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                //buildTZGG();
                //buildGZJB();
                string value = Usual.f_querystringToString("value");
                string newsid = Usual.f_querystringToString("newsid");
                if (newsid != "" && newsid != null)
                {
                    if (value =="6")
                    {
                        showmq(value,newsid);
                    }
                    else
                    { 
                        shownews(newsid);
                    }
                }
              

            }
        }
        protected void F_FJ(string newsid)
        {
            if (newsid != "" && newsid != null)
            {
                Hashtable htab = new Hashtable();
                htab.Add("@NewsId",newsid);
                DataSet dst = new SqlReadXml().ReaderDataSet("select_tabfile", htab);
                if (dst.Tables.Count > 0)
                {
                    Repeater1.DataSource = dst;
                    Repeater1.DataBind();
                }
            }
        }
        protected void showmq(string value, string newid)
        {
            Hashtable htable = new Hashtable();
            htable.Add("@tabids", newid);
            DataSet ds = new DataReturn().ReturnData(htable, "sel_mq_byid");
            foreach (DataRow dr in ds.Tables[0].Rows)
            {
                dr["NewsID"] = dr["tabids"].ToString();
                dr["NewsTitles"] = dr["mqdate"].ToString().Substring(0, 8) + " " + dr["lgname"].ToString() + "民情日记";
                dr["showtitle"] = dr["mqdate"].ToString().Substring(0, 8) + " " + dr["lgname"].ToString() + "民情日记";
                dr["FBdate"] = dr["mqdate"].ToString().Substring(0, 8);
            }
            this.news.InnerHtml = ds.Tables[0].Rows[0]["MQRJ"].ToString().Replace("^", "\n");//新闻内容
            this.fatime.InnerHtml = "发布时间：" + Usual.f_convertDateTime(ds.Tables[0].Rows[0]["mqdate"].ToString()).ToShortDateString();//新闻时间
            this.newstitle.InnerHtml = ds.Tables[0].Rows[0]["mqtitle"].ToString();//新闻标题
            this.menuid.Value = value;
        }
        /// <summary>
        /// 根据新闻id获取新闻内容
        /// </summary>
        /// <param name="newid">新闻id</param>
        protected void shownews(string newid)
        {
            //news
            Hashtable htable = new Hashtable();
            htable.Add("@newsid", newid);
            DataSet ds = new DataReturn().ReturnData(htable,"sel_news_byid");
            if (ds != null)
            {
                if (ds.Tables[0].Rows.Count > 0)
                {
                    this.news.InnerHtml = ds.Tables[0].Rows[0]["Newscontent"].ToString().Replace("^","\n");//新闻内容
                    this.fatime.InnerHtml = "发布时间："+Usual.f_convertDateTime(ds.Tables[0].Rows[0]["FBdate"].ToString()).ToShortDateString();//新闻时间
                    this.newstitle.InnerHtml = ds.Tables[0].Rows[0]["NewsTitles"].ToString();//新闻标题
                    this.menuid.Value = ds.Tables[0].Rows[0]["BTSBLMName"].ToString();
                    //if (ds.Tables[0].Rows[0]["BTSBLMName"].ToString() == "1")
                    //{
                          //string newsid = Usual.f_querystringToString("newsid");
                        F_FJ(newid);
                    //}
                }
            }
            
        }

        //绑定通知公告
        //protected void buildTZGG()
        //{
        //    Hashtable htable = new Hashtable();

        //    htable.Add("@BTSBLMName", "1");
        //    DataSet ds = new DataReturn().ReturnData(htable, "sel_sydtxw_all");
        //    if (ds != null)
        //    {

        //        tzgg.DataSource = cutTitle(ds);
        //        tzgg.DataBind();
        //    }
        //}


        ////绑定工作简报
        //protected void buildGZJB()
        //{
        //    Hashtable htable = new Hashtable();

        //    htable.Add("@BTSBLMName", "5");
        //    DataSet ds = new DataReturn().ReturnData(htable, "sel_sydtxw_all");
        //    if (ds != null)
        //    {

        //        gzjb.DataSource = cutTitle(ds);
        //        gzjb.DataBind();
        //    }
        //}


        /// <summary>
        /// 若标题过长  截取标题
        /// </summary>
        /// <param name="ds"></param>
        /// <returns></returns>
        protected DataSet cutTitle(DataSet ds)
        {
            if (ds.Tables[0].Rows.Count > 0)
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    if (dr["NewsTitles"].ToString().Length >16)
                    {
                        dr["showtitle"] = dr["NewsTitles"].ToString().Substring(0, 16) + "...";
                    }
                    else
                    {
                        dr["showtitle"] = dr["NewsTitles"].ToString();
                    }
                }
            }
            return ds;
        }
    }
}